/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pracamagisterska;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Adrian
 */
public class Configuration extends ModalityInternalFrame {
private static final String EMAIL_PATTERN =  "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private DatabaseThread db;
private boolean typ;
private ArrayList<String> settings;
private BufferedImage image;
private FileInputStream fin;
    /**
     * Creates new form Configuration
     */
    public Configuration(JComponent parent, DatabaseThread db, String [] list) throws SQLException {
        super(parent,db,list);
        initComponents();
        this.db = db;
        this.typ = typ;
        //funkcjonalność możliwa do rozwinięcia w przyszłosci:
        jComboBox1.setVisible(false);
        jTextField5.setVisible(false);
        jLabel7.setVisible(false);
        jLabel9.setVisible(false);
        //--koniec
        jButton2.setEnabled(false);
        jLabel10.setVisible(false);
        jLabel11.setVisible(false);
        jLabel12.setVisible(false);
        jLabel13.setVisible(false);
        jLabel14.setVisible(false);
        jLabel15.setVisible(true);
        jLabel15.setText("Pierwsza konfiguracja - uzupełnij pola!");
        jLabel16.setVisible(false);
        jRadioButton1.setVisible(false);
        jRadioButton2.setVisible(false);
        for(int i =0; i < list.length ; i++){
           jComboBox1.addItem(list[i]);           
        }        
    }
     public Configuration(JComponent parent, DatabaseThread db, String [] list, ArrayList<String> settings) throws SQLException {
        super(parent,db,list,settings);
        initComponents();
        this.db = db;
        this.typ = typ;
        this.settings=settings;
        this.setClosable(true);
        this.setIconifiable(true);
        //funkcjonalność możliwa do rozwinięcia w przyszłosci:
        jComboBox1.setVisible(false);
        jTextField5.setVisible(false);
        jLabel7.setVisible(false);
        jLabel9.setVisible(false);
        //--koniec
        jButton2.setEnabled(true);
        jLabel10.setVisible(false);
        jLabel11.setVisible(false);
        jLabel12.setVisible(false);
        jLabel13.setVisible(false);
        jLabel14.setVisible(false);
        jLabel15.setVisible(true);
        jLabel16.setVisible(true);
        jRadioButton1.setVisible(true);
        jRadioButton2.setVisible(true);
        for(int i =0; i < list.length ; i++){
           jComboBox1.addItem(list[i]);           
        }  
        jComboBox1.setSelectedItem(settings.get(0));
        jTextField1.setText(settings.get(1));
        jTextField2.setText(settings.get(2));
        jTextField3.setText(settings.get(3));
        if(settings.get(4).equals("1")) jRadioButton1.setSelected(true); 
        else jRadioButton2.setSelected(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jPasswordField2 = new javax.swing.JPasswordField();
        jTextField3 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jLabel16 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setForeground(java.awt.Color.white);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_tool.png"))); // NOI18N

        jLabel2.setText("Nazwa hotelu:");

        jButton1.setText("Zapisz");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Nazwa użytkownika:");

        jLabel4.setText("Hasło:");

        jLabel5.setText("Powtórz hasło:");

        jLabel6.setText("Adres e-mail:");

        jLabel7.setText("Język:");

        jTextField4.setEditable(false);

        jTextField5.setEditable(false);

        jLabel8.setText("Logo hotelu:");

        jLabel9.setText("Tapeta pulpitu:");

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel10.setToolTipText("Nazwa hotelu jest zbyt krótka");

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel11.setToolTipText("Nazwa użytkownika jest zbyt krótka");

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel12.setToolTipText("Hasła nie zgadzają się");

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel13.setToolTipText("Hasło powinno posiadać mimimum 5 znaków");

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel14.setToolTipText("Niepoprawny adres e-mail");

        jButton2.setText("Anuluj");
        jButton2.setToolTipText("");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_help_small.png"))); // NOI18N
        jLabel15.setText("<html>Aby zmienić hasło wprowadź nowe lub pozostaw pole puste aby zachować obecne</html>\n");

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Tak");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Nie");

        jLabel16.setText("Pokaż powitanie:");

        jButton3.setText("Wybierz");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Usuń");
        jButton4.setEnabled(false);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(154, 154, 154))
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel16))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField1)
                            .addComponent(jTextField2)
                            .addComponent(jPasswordField1)
                            .addComponent(jPasswordField2)
                            .addComponent(jTextField3)
                            .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButton1)
                                .addGap(18, 18, 18)
                                .addComponent(jRadioButton2))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                                    .addComponent(jTextField5))
                                .addGap(9, 9, 9)
                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3)))
                        .addGap(9, 9, 9))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel1)
                        .addGap(50, 50, 50))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3))
                    .addComponent(jLabel11))
                .addGap(5, 5, 5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4))
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(jButton3)
                            .addComponent(jButton4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)))
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7))
        );

        jLabel13.getAccessibleContext().setAccessibleDescription("Hasło powinno posiadać pomiędzy 5 a 30 znaków");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String language = jComboBox1.getSelectedItem().toString();
        String name = jTextField1.getText();
        String user = jTextField2.getText();
        String pass = jPasswordField1.getText();
        String pass2 = jPasswordField2.getText();
        String mail = jTextField3.getText(); 
        
        int status = 0;               
        if(settings==null){
            if(validateName(name)) status++;
            if(validateUser(user)) status++;        
            if(validateMail(mail)) status++;
            if(validatePassLength(pass)) status++;
            if(validatePass(pass,pass2)) status++;
            byte [] bytes=null;
            if(status==5) {
                try {
                        if(image==null || jTextField4.equals("")) bytes = null;
                        else{
                            ByteArrayOutputStream bas = new ByteArrayOutputStream();
                            ImageIO.write(resize(image),"png", bas);
                            bytes=bas.toByteArray();
                        }
                        if(db.configuration_new(jComboBox1.getSelectedItem().toString(), name, user, db.MD5(pass), mail,bytes)){
                            this.dispose();
                            db.window2();
                        }
                } catch (IOException ex) {
                    Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
                }
                catch (SQLException | NoSuchAlgorithmException ex) {
                        Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
                }
            }            
        }
        else{
            if(validateName(name)) status++;
            if(validateUser(user)) status++;        
            if(validateMail(mail)) status++;
            byte [] bytes=null;

            if(pass.equals("") && pass2.equals("")) {
                if (status==3){
                    try {                        
                        if(image==null || jTextField4.equals("")) bytes = null;
                        else{
                            ByteArrayOutputStream bas = new ByteArrayOutputStream();
                            ImageIO.write(resize(image),"png", bas);
                            bytes=bas.toByteArray();
                        }
                        if(db.configuration_change(jComboBox1.getSelectedItem().toString(), name, user, null, mail, jRadioButton1.isSelected()? 1:0,bytes)){
                                this.dispose();
                        }
                    } catch (IOException | SQLException ex) {
                        Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }                
            }
            else {
                if(validatePassLength(pass)) status++;
                if(validatePass(pass,pass2)) status++;
                if (status==5){
                    try {
                        InputStream is =null;
                        if(image==null || jTextField4.equals("")) bytes = null;
                        else{
                            ByteArrayOutputStream bas = new ByteArrayOutputStream();
                            ImageIO.write(resize(image),"png", bas);
                            is = new ByteArrayInputStream(bas.toByteArray());
                        }
                        if(db.configuration_change(jComboBox1.getSelectedItem().toString(), name, user, db.MD5(pass), mail, jRadioButton1.isSelected()? 1:0,bytes)){
                                this.dispose();
                            }
                        } catch (IOException ex) {
                        Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (NoSuchAlgorithmException | SQLException ex) {
                        Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
                        
                    }
                }    
            }
        }     
    }//GEN-LAST:event_jButton1ActionPerformed

    private BufferedImage resize(BufferedImage img){
        BufferedImage resizedImage = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = resizedImage.createGraphics();
        g.drawImage(img, 0, 0, 300, 200, null);
        g.dispose();
        return resizedImage;
    }
    
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            final JFileChooser fc = new JFileChooser();
            //fc.addChoosableFileFilter(new ImageFilter());
            fc.setAcceptAllFileFilterUsed(false);
            if (evt.getSource() == jButton3) {
            fc.setFileFilter(new ImageFilter());
            int returnVal = fc.showOpenDialog(this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                fin = new FileInputStream(file);
                jTextField4.setText(file.getName());
                jButton4.setEnabled(true);
                image = ImageIO.read(file);
                
                if(image.getWidth()!=300 || image.getHeight()!=200){
                    ModalityInternalFrame er = new Error(this,"<html><center>Obraz nie spełnia wymaganych wymiarów: 300 x 200.<br>Zostanie on przeskalowany</center></html>");
                    JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);           
                    desktop.add(er);
                    er.show(); 
                }else{
                    ModalityInternalFrame ic = new ImageCrop(this,image);
                    JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);           
                    desktop.add(ic);
                    ic.show(); 
                }
                System.out.println("Opening: " + file.getName() + ".");
            } else {
                System.out.println("Open command cancelled by user.");
            }
       } 
        } catch (IOException ex) {
            Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    public void openImageCrop() {
        ModalityInternalFrame ic = new ImageCrop(this,image);
        JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);           
        desktop.add(ic);
        ic.show(); 
    }
    
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        jTextField4.setText("");        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private boolean validateName(String name){
        if(name!=null && name.length()>3) {
            jLabel10.setVisible(false);
            jTextField1.setBackground(Color.white);
            return true;
        }
        else jLabel10.setVisible(true);
        jTextField1.setBackground(Color.YELLOW);
        return false;
    }
    private boolean validateUser(String user){
        if(user!=null && user.length()>3) {
            jLabel11.setVisible(false);
            jTextField2.setBackground(Color.white);
            return true;
        }
        jLabel11.setVisible(true);
        jTextField2.setBackground(Color.YELLOW);
        return false;
    }
    private boolean validatePassLength(String pass1){
        if (pass1!=null && pass1.length()>=5 && pass1.length()<=30 ) {
            jLabel13.setVisible(false);
            jPasswordField1.setBackground(Color.white);
            return true;
        }
        jLabel13.setVisible(true);
        jPasswordField1.setBackground(Color.YELLOW);
        return false;
    }
    private boolean validatePass(String pass1,String pass2){
        if (pass1.equals(pass2)) {
            jLabel12.setVisible(false);
            jPasswordField2.setBackground(Color.white);
            return true;
        }
        jLabel12.setVisible(true);
        jPasswordField2.setBackground(Color.YELLOW);
        return false;
    }
    private boolean validateMail(String mail){
        Pattern pattern = Pattern.compile(EMAIL_PATTERN);
        Matcher matcher = pattern.matcher(mail);
        if (matcher.matches()) {
            jLabel14.setVisible(false);
            jTextField3.setBackground(Color.white);
            return true;
        }
        jLabel14.setVisible(true);
        jTextField3.setBackground(Color.YELLOW);
        return false;
    }
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    protected javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JPasswordField jPasswordField2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
}
